<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card-body">
        <form class="layui-form toolbar" lay-filter="binTbForm">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">数据搜索:</label>
                    <div class="layui-input-inline">
                        <input name="title" class="layui-input" placeholder="输入内容名称"/>
                    </div>
                </div>
                <div class="layui-inline">&nbsp;
                    <button class="layui-btn layui-btn-sm icon-btn" lay-filter="binBinBinTbImg" lay-submit>
                        <i class="layui-icon">&#xe615;</i>搜索
                    </button>
                </div>
            </div>
        </form>
        <table id="contentRecycleTable" lay-filter="contentRecycleTable"></table>
    </div>
</div>
<!-- 表格操作列 -->
<script type="text/html" id="contentRecycleTbBar">
    <a class="layui-btn layui-btn-xs" lay-event="reRecycle">还原内容</a>
</script>

<!-- js部分 -->
<script>
    layui.use(['layer', 'admin', 'form', 'table', 'formX', 'laytpl', 'setter', 'dropdown', 'notice'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var admin = layui.admin;
        var form = layui.form;
        var table = layui.table;
        var setter = layui.setter;
        var notice = layui.notice;
        // 渲染表格
        var binInsTb = table.render({
            elem: '#contentRecycleTable',
            url: setter.baseServer + '/content/content_list',
            where: {is_del: 1},
            page: true,
            limit: 7,
            limits: [10, 20],
            height: 'full-405',
            defaultToolbar: [],
            cols: [[
                {field: 'id', title: 'id', width: 80, minWidth: 80},
                {
                    title: '封面', templet: function (d) {
                        var url = d.images || '';
                        return '<img data-index="' + (d.LAY_INDEX - 1) + '" src="' + url + '" class="tb-img-circle" tb-img alt="" style="width: 50px;"/>';
                    }, align: 'center', width: 70, unresize: true
                },
                {field: 'title', title: '标题'},
                {field: 'cate_name', title: '分类', width: 100, minWidth: 100, align: 'left'},
                {field: 'remark', title: '描述', width: 200, align: 'left'},
                {title: '操作', toolbar: '#contentRecycleTbBar', align: 'center', width: 200, minWidth: 200}
            ]],
            size: 'lg'
        });
        /* 表格搜索 */
        form.on('submit(binBinBinTbImg)', function (data) {
            binInsTb.reload({where: data.field});
            return false;
        });

        /* 表格工具条点击事件 */
        table.on('tool(contentRecycleTable)', function (obj) {
            if (obj.event === 'reRecycle') {
                getRecycleBin(obj);
            }
        });

        /* 还原内容 */
        function getRecycleBin(obj) {
            admin.confirm('确定要还原选中数据吗？', function (i) {
                layer.closeAll();
                notice.msg('加载中...', {icon: 4});
                var data = {};
                data.id = obj.data.id;
                data.is_del = 0;
                admin.req(setter.baseServer + '/content/content_status', data, function (res) {
                    notice.destroy();
                    if (200 === res.code) {
                        notice.msg('内容已还原', {icon: 1});
                        admin.putLayerData('formOk', true, '#contentRecycleTable');  // 设置操作成功的标识
                    } else {
                        notice.msg(res.msg, {icon: 2});
                    }
                }, 'post');
            });
        }

    });
</script>
